﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MiserBlogData.Helper;
using MiserDB.DataHelp;
using System.Web.Mvc;

namespace MiserBlogData.Entities
{
    public class Categories : A_DataProperty, IParseRightBar
    {
        public virtual IList<Article> Articles { get; set; }
        //public virtual UserVIP Person { get; set; }

        //public void ProduceLeftBar()
        //{

        //}

        public virtual string ParseRightBar(object needParseObj)
        {



            string reHtml = string.Empty;
            if (needParseObj is RightBarHelper)
            {
                RightBarHelper helper = (RightBarHelper)needParseObj;
                StringBuilder sb = new StringBuilder();
                foreach (var item in helper.Person.CategoriesList)
                {
                    sb.Append(string.Format(helper.ContentHtml, item.Name, item.Articles.Count));
                }
                reHtml = sb.ToString();
            }
            
            
            return reHtml;
        }

        public static IEnumerable<SelectListItem> GetSelf(int vipId )
        {
            MiserDB.DataHelp.QueryHelper dh = new QueryHelper();
            IList<Categories> list = dh.GetSelfPage<Categories>(vipId, null);
            List<SelectListItem> selectList = new List<SelectListItem>();
            selectList.Add(new SelectListItem { Text = "请选择", Value = string.Empty });
            foreach (var item in list)
            {
                SelectListItem selectItem = new SelectListItem();
                selectItem.Value = item.Id.ToString();
                selectItem.Text = item.Name;
                selectList.Add(selectItem);
            }
            return selectList;
        }
    }
}
